package com.perkinelmer.housecall.client.activities.patientdetails;

import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SingleSelectionModel;
import com.perkinelmer.housecall.client.model.Observation;

public class IncidentTable extends CellTable<Observation> {

	private static final TextColumn<Observation> TYPE_COL = new TextColumn<Observation>() {
		public String getValue(Observation observation) {
			return observation.getId().toString();
		}
	};
	
	private static final TextColumn<Observation> DATE_COL = new TextColumn<Observation>() {
		public String getValue(Observation observation) {
			return observation.getDateString();
		}
	};
	
	private static final TextColumn<Observation> TIME_COL = new TextColumn<Observation>() {
		public String getValue(Observation observation) {
			return observation.getTimeString();
		}
	};
	
	private static final TextColumn<Observation> DESCRIPTION_COL = new TextColumn<Observation>() {
		public String getValue(Observation observation) {
			return observation.getDescription();
		}
	};
	
	private final ListDataProvider<Observation> model;
	
	public IncidentTable() {
		addColumn(TYPE_COL, "Type");
		addColumn(DATE_COL, "Date");
		addColumn(TIME_COL, "Time");
		addColumn(DESCRIPTION_COL, "Description");
		
		model = new ListDataProvider<Observation>();
		model.addDataDisplay(this);
		
		setSelectionModel(new SingleSelectionModel<Observation>());
	}
	
	public void clear() {
		model.getList().clear();
		model.refresh();
	}
	
	public void addObservation(Observation observation) {
		model.getList().add(observation);
		model.refresh();
	}
}
